//
//  TTVerticalScrollADView.m
//  TaoTuo
//
//  Created by admin on 2020/1/7.
//  Copyright © 2020 admin. All rights reserved.
//

#import "TTScrollADView.h"
#import <UIImageView+WebCache.h>
#import "TTScrollDisplayADModel.h"

@interface TTScrollADView ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subTitleLabel;
@property (nonatomic, strong) UIButton *btn;
@property (nonatomic, strong) TTScrollDisplayADModel *model;

@end

@implementation TTScrollADView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColorHex(FAF5FF);
        self.layer.cornerRadius = 5;
        [self setupSubviews];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lookAllAction)];
        [self addGestureRecognizer:tap];
        
    }
    return self;
}

- (void)setupData:(id)data
{
    self.model = (TTScrollDisplayADModel *)data;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.model.ImageUrl] placeholderImage:[UIImage imageNamed:@"home_quan"] options:SDWebImageRetryFailed];
    
    self.titleLabel.text = self.model.Name;
    self.subTitleLabel.text = self.model.Description;
    
    NSString *btnTitle = self.model.ButtonName ? : @"查看";
    [self.btn setTitle:btnTitle forState:UIControlStateNormal];
    
}

///查看全部
- (void)lookAllAction
{
    [LLRouteTool skipViewControllerWIthSkipType:self.model.SkipType skipTarget:self.model.SkipTarget];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imageView.frame = CGRectMake(7, 7 * kScale, 35 * kScale, 35 * kScale);
    
    self.btn.frame = CGRectMake(self.right - 80, 0, 70, self.height);
    
    self.titleLabel.frame = CGRectMake(self.imageView.right + 10, self.imageView.top, self.width - self.imageView.right - 10 - self.btn.width - 10, 22 * kScale);
    self.subTitleLabel.frame = CGRectMake(self.titleLabel.left, self.titleLabel.bottom, self.titleLabel.width, 15 * kScale);
    
    
}

- (void)setupSubviews
{
    _imageView = [[UIImageView alloc] init];
    _imageView.image = [UIImage imageNamed:@"home_quan"];
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    _imageView.layer.masksToBounds = YES;
    [self addSubview:_imageView];
    
    _btn = [UIButton createButtonWithTitle:@"查看" titleColor:kMainColor titleFont:[UIFont systemFontOfSize:15] backgroundColor:nil target:self action:@selector(lookAllAction)];
    _btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self addSubview:_btn];
    
    _titleLabel = [UILabel labelWithTitle:@"新用户无门槛优惠券5元" color:UIColorHex(333333) fontSize:13];
    [self addSubview:_titleLabel];
    
    
    _subTitleLabel = [UILabel labelWithTitle:@"2019.03.25-2019.04.25" color:kMainColor fontSize:10];
    [self addSubview:_subTitleLabel];
    
    
    
}


@end
